home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPANS.ZIP / BITDATE.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  882b  |  36 lines

  1. // bitdate.cpp -- Pack date and time in a bit-field struct
  2.  
  3. #include <iostream.h>
  4.  
  5. struct dnt {
  6.   char month, day;
  7.   int year;
  8.   char hour, minute, second;
  9. };
  10.  
  11. struct packdnt {
  12.   unsigned month  : 4;    // 0 .. 11 (max == 15)
  13.   unsigned day    : 5;    // 1 .. 31 (max == 31)
  14.   unsigned year   : 6;    // 0 .. 59 (assume base = 1980)
  15.   unsigned hour   : 5;    // 0 .. 23 (max = 31)
  16.   unsigned minute : 6;    // 0 .. 59 (max = 63)
  17. //   unsigned second : 6;    // 0 .. 59 (max = 63)
  18. };
  19.  
  20. main()
  21. {
  22.   dnt regular;
  23.   packdnt compressed;
  24.  
  25.   cout << "Size of regular dnt = " << sizeof(regular);
  26.   cout << "\nSize of packed dnt = " << sizeof(compressed);
  27. }
  28.  
  29.  
  30. // Copyright (c) 1990 by Tom Swan. All rights reserved
  31. // Revision 1.00    Date: 10/24/1990   Time: 09:24 am
  32.  
  33. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  34. // Converted for Borland C++ 2.0
  35.  
  36.